<?php
class Category extends AppModel {

	var $name = 'Category';
    var $primaryKey = 'category_id';
    var $hasMany = array('Post');

    /**
     * Checking whether category is exist or not
     * usage in : Category Controller -> function add()
     */
    function checkCategoryExist($category){
        $this->recursive = -1;
        $result = $this->find('first',array(
            'fields'=>'Category.category_id',
            'conditions'=>array('AND'=>array('Category.name'=>$category,'Category.status'=>'1'))));

        return $result;
    }

   /**
    * Get Category list
    * usage in : Category Controller -> category()
    */
	function categoryList(){
		$this->recursive = -1;
		$results = $this->find('all',array(
			'conditions'=>array('Category.status'=>'1'),
			'fields'=>'Category.category_id, Category.name'));

		return $results;
	}
}
?>
